<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>4_运算符</title>
</head>
<body>

<script>
    console.log(6/3);
    console.log(1/3);
    /*比较运算符左右两侧有一个是字符串，会转为数字*/
    console.log(3>10);
    console.log('3'>10);
    console.log(3>'10');
    /*两边都是字符串，会比较字符串的编码值*/
    console.log('3'>'10');

    console.log('梓'>'自')
    console.log('涂山美美'.charCodeAt())/*默认是第一个字的编码值*/
    console.log('涂山美美'.charCodeAt(0))

    /*字符串、boolean转数字*/
    console.log(Number('2'),typeof Number('2'));
    console.log(Number(true),typeof Number(true));
    console.log(Number(false),typeof Number(false));
    console.log(Number('你好'),typeof Number('你好'));/*若转不成功，会得到：NaN Not a Number*/

    let a = 1;
    let b = true;
    /*松散比较：只比较值，存在隐式类型转换：Number(true)=1*/
    console.log(Number(b));
    console.log(a==b);
    /*严格比较：先比较数据类型，再比较值*/
    console.log(a===b);

    /*三元运算符*/
    let c = 0;
    console.log(c==0?'yes':'no');
    console.log(c=0?'yes':'no');/*Boolean(0)=false*/

    /**/
    console.log('************')
    console.log(Boolean(0));
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean(''));
    /*若参数是0、null、undefined、NaN、''转为布尔都是false，其余是true*/
    console.log('***')
    console.log(Boolean('  '));
    console.log(Boolean('涂山'));
</script>
</body>
</html>